<template>
    <div>
        <base-list ref="yardMsg" :condition="condition" :datas.sync="yardMsg" :pageSearch="pageSearch">
            <el-form :inline="true" :model="condition" class="search-form" slot="search" label-width="100px">
                <el-row>
                    <el-col :span="8">
                        <el-form-item label="场区">
                            <!--<el-input v-model="condition['search_LIKE_areaNo']"></el-input>-->
                            <auto-search-area-no v-model="condition['search_LIKE_areaNo']"></auto-search-area-no>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-button type="primary" icon="el-icon-search" @click="loadData">查 询</el-button>
                        <el-button formVisible="true" icon="el-icon-plus" @click="handleDialogFormOpen(false)" v-if="power('WJOB_YARDPLAN_YARDMGR:ADD')">
                            新增
                        </el-button>
                    </el-col>
                </el-row>
            </el-form>
            <el-table slot="list" :data="yardMsg" border stripe max-height="500">
                <el-table-column prop="areaNo" label="场位"  min-width="90"></el-table-column>
                <el-table-column prop="orgName" label="所属单位"  min-width="200"></el-table-column>
                <el-table-column prop="deptName" label="所属部门"  min-width="120"></el-table-column>
                <el-table-column prop="maxBay" label="最大贝位号"  min-width="120"></el-table-column>
                <el-table-column prop="maxRow" label="最大排位数"  min-width="120"></el-table-column>
                <el-table-column prop="maxTier" label="最大层高数"  min-width="120"></el-table-column>
                <el-table-column prop="bayDirection" label="贝号方向"  min-width="120">
                    <template slot-scope="scope">
                        {{ scope.row.bayDirection | _filterSOrB }}
                    </template>
                </el-table-column>
                <el-table-column prop="virtual" label="虚拟场区"  min-width="110">
                    <template slot-scope="scope">
                        {{ scope.row.virtual | _filterTrueOrFalse }}
                    </template>
                </el-table-column>
                <el-table-column prop="allowedOut" label="允许出场"  min-width="110">
                    <template slot-scope="scope">
                        {{ scope.row.allowedOut | _filterTrueOrFalse }}
                    </template>
                </el-table-column>
                <el-table-column prop="stackOrder" label="堆放顺序"  min-width="120">
                    <template slot-scope="scope">
                        {{ scope.row.stackOrder | _filterStackOrder }}
                    </template>
                </el-table-column>
                <el-table-column prop="totalTeu" label="标箱容量"  min-width="110"></el-table-column>
                <el-table-column prop="controlfieldTeu" label="布控场位"  min-width="110"></el-table-column>
                <el-table-column prop="enabledTeu" label="可用场位"  min-width="110"></el-table-column>
                <el-table-column prop="remark" label="场区说明"  min-width="120"></el-table-column>
                <el-table-column prop="createBy" label="修改人"  min-width="120"></el-table-column>
                <el-table-column prop="createDateTime" label="修改时间"  min-width="160"></el-table-column>
                <el-table-column fixed="right" align="center" label="操作"  width="140">
                    <template slot-scope="scope">
                        <el-button size="small" type="text" @click="handleDialogFormOpen(true,scope.row)" v-if="power('WJOB_YARDPLAN_YARDMGR:UPD')">
                            编辑
                        </el-button>
                        <el-button type="text" class="danger" size="small" @click="handleRemove(scope.row)" v-if="power('WJOB_YARDPLAN_YARDMGR:DEL')">删除
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
        </base-list>
        <yard-msg-form ref="yardMsgForm" @load="loadData"></yard-msg-form>
    </div>
</template>

<script>
    import { deleteYardMsg, getYardMsgList } from "@/api/yardPlan/yardPlan";
    import yardMsgForm from './yardMsgForm'
    import autoSearchAreaNo from '@/components/autocomplete/autoSearchAreaNo'
    export default {
        name: "堆场管理",
        components: {
            yardMsgForm,
            autoSearchAreaNo
        },
        data() {
            return {
                condition: {}, // 查询条件
                yardMsg: [], // table数组
                pageSearch: getYardMsgList, // 分页查询api接口
                id: ''
            }
        },
        mounted() {
            this.$nextTick(() => {
                this.loadData()
            })
        },
        methods: {
            loadData() {
                this.$refs.yardMsg.loadData()
            },
            handleDialogFormOpen(bool, item) {
                if (bool) {
                    let form = JSON.parse(JSON.stringify(item))
                    this.$refs.yardMsgForm.form = {
                        id:form.id,
                        areaNo:form.areaNo,
                        maxBay:form.maxBay,
                        maxRow:form.maxRow,
                        maxTier:form.maxTier,
                        bayDirection:form.bayDirection,
                        virtual:form.virtual,
                        allowedOut:form.allowedOut,
                        orgId:form.orgId,
                        orgName:form.orgName,
                        deptId:form.deptId,
                        deptName:form.deptName,
                        stackOrder:form.stackOrder,
                        totalTeu:form.totalTeu,
                        controlfieldTeu:form.controlfieldTeu,
                        remark:form.remark,
                        enabledTeu:form.enabledTeu,
                    }
                    this.$refs.yardMsgForm.isEdit = true
                    this.$refs.yardMsgForm.dialogForm = true
                } else {
                    this.$refs.yardMsgForm.dialogForm = true
                }
            },
            handleRemove(item) {
                this.$confirm(`是否删除该数据?`, '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    deleteYardMsg(item.id).then(res => {
                        this.$message({
                            type: 'success',
                            message: `删除成功!`
                        });
                        this.loadData()
                    })
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消'
                    });
                });
            }
        },
    }

</script>

<style scoped>


</style>
